import java.util.HashSet;

public class HashSetTest {

    public static void main(String[] args) {

//        String a = "abc";
//        String b = "abc";
//        StringBuilder a = new StringBuilder("abc");
//        StringBuilder b = new StringBuilder("abc");

        String a = new String("abc");
        String b = new String("abc");

        String c = "abc";//没用，搭不上边 人家是new的 new的不在字符串常量池里

        System.out.println(a == b);
        System.out.println(a.equals(b));

//        System.out.println(a == c);         //false，地址不一样
//        System.out.println(a.equals(c));    //true，值一样

        HashSet hashSet1 = new HashSet();
        hashSet1.add(a);
        hashSet1.add(b);
        System.out.println(hashSet1.size());

        Person person1 = new Person("abc");
        Person person2 = new Person("abc");

        System.out.println(person1 == person2);
        System.out.println(person1.equals(person2));

        HashSet hashSet2 = new HashSet();
        hashSet2.add(person1);
        hashSet2.add(person2);
        System.out.println(hashSet2.size());

    }

}

class Person {
    String name;
    int id;

    public Person(String name) {
        this.name = name;
    }
}
